package com.bing.e724;

public class Run {

	public static void main(String[] args) {
        //在main组中添加一个线程组A,然后在这个A组中添加线程对象Z
		//方法activeGroupCount()和activeCount()的值是不固定的，是系统中环境的一个快照。
		
		ThreadGroup mainGroup=Thread.currentThread().getThreadGroup();
		ThreadGroup group=new ThreadGroup(mainGroup, "A");//把线程组A添加到线程组mainGroup中。
		
		Runnable runnable=new Runnable(){

			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					while(!Thread.currentThread().isInterrupted()){
						System.out.println("runMethod!");
						Thread.sleep(10000);//线程必须在运行状态才可以受组管理
					}
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		};
			Thread newThread=new Thread(mainGroup, runnable);//把线程runnable添加到线程组mainGroup中。
			newThread.setName("Z");
			newThread.start();
			
			ThreadGroup[] groupList=new ThreadGroup[Thread.currentThread().getThreadGroup().activeGroupCount()];
			Thread.currentThread().getThreadGroup().enumerate(groupList);
			
			System.out.println("mian线程中有多少个子线程组： "+groupList.length+" 名称为："+groupList[0].getName());
			
			Thread[] threadList=new Thread[groupList[0].activeCount()];
			groupList[0].enumerate(threadList);
			
			System.out.println(groupList[0].getName());
			
		
	}

}
